﻿using System;

namespace ShapeCalculator
{
    // 简单工厂类
    public static class ShapeFactory
    {
        //创建私有静态的Random对象 用于工厂类内部生成随机数
        private static Random random = new Random();

        // 随机创建形状对象
        public static IShape CreateRandomShape()
        {
            switch (random.Next(1, 4)) // 随机选择形状类型
            {
                case 1:
                    Console.WriteLine("随机创建长方形");
                    return CreateRandomRectangle();
                case 2:
                    Console.WriteLine("随机创建正方形");
                    return CreateRandomSquare();
                case 3:
                    Console.WriteLine("随机创建三角形");
                    return CreateRandomTriangle();
                default:
                    throw new InvalidOperationException("不合理的形状");
            }
        }

        // 随机创建长方形
        private static Rectangle CreateRandomRectangle()
        {
            double length = random.NextDouble() * 10; // 长度范围在0到10之间
            double width = random.NextDouble() * 10; // 宽度范围在0到10之间
            return new Rectangle(length, width);
        }

        // 随机创建正方形
        private static Square CreateRandomSquare()
        {
            double sideLength = random.NextDouble() * 10; // 边长范围在0到10之间
            return new Square(sideLength);
        }

        // 随机创建三角形
        private static Triangle CreateRandomTriangle()
        {
            //三边长度在0-10之间
            double sideA = random.NextDouble() * 10; 
            double sideB = random.NextDouble() * 10; 
            double sideC = random.NextDouble() * 10; 
            return new Triangle(sideA, sideB, sideC);
        }
    }
}